import { Sparklines, SparklinesLine, SparklinesReferenceLine } from 'react-sparklines'

function Sparkline(props: any) {
  // 计算平均值
  function average(data: any) {
    return data.reduce((acc: number, val: number) => acc + val, 0) / data.length
  }

  return (
    <div>
      <Sparklines data={props.data} width={180} height={100}>
        <SparklinesLine color={props.color} />
        <SparklinesReferenceLine type="mean" />
      </Sparklines>
      <div className="font-sans" style={{ color: props.color }}>
        平均值: {average(props.data).toFixed(1)}
        {props.label}
      </div>
    </div>
  )
}

export default Sparkline
